/**
 * @ author: 汪孟苹
 */
define(["jquery",
	"scprit/followup/app/workBench/workBenchs.servers.js",
	"scprit/followup/app/workBench/workBenchs.ui.js",
	"scprit/followup/app/workBench/workBenchs.event.js"],
	function($,$workBenchServers,$workBenchUi,$workBenchEvent){
	var workBench = {};

	/**
	 * 请求统计数据成功后的回调函数
	 */
	var ajaxStatisCallBack = function(data){
		$workBenchUi.windowPtInit({
			id:"windowBottomStatistics",
			list: data
		});
		$workBenchUi.windowTopInit({
			id:"dashboardCardlist",
			list: data
		});
		$(".dashboard-add #addPatient").click($workBenchEvent.onAddPatientClick);
	}
	/**
	 * 请求队列成功后的回调函数
	 */
	var ajaxQueueCallBack = function(rows){
		$workBenchUi.selectQueueInit({
			id: "selectQueue",
			list: rows
		});
	}
	/**
	 * 请求今日门诊记录成功后的回调函数
	 */
	var ajaxPatientsOperateCallBack = function(rows){
		$workBenchUi.windowRightInit({
			id:"patientOperateListQuery",
			list:rows
		});
		$("#patientOperateListQuery .baby-done").data({"value":rows});
		$("#patientOperateListQuery .baby-done").click($workBenchEvent.onBabyClick);
	}

	workBench.init = function(){

		getWindowConfigAndSetGlobal()

		$workBenchEvent.initVue()

		$workBenchServers.ajaxStatis(ajaxStatisCallBack);
		var params1 = {
			"page":1,
			"rows":11,
			"flag":"0"
		};
		$workBenchServers.ajaxPatientsOperate(params1,ajaxPatientsOperateCallBack);	// 今日门诊
		var rows;
		if( document.body.offsetWidth < 992 ){
			rows = 2;
		}else if( document.body.offsetWidth <1200 ){
			rows = 3;
		}else{
			rows = 4;
		}
		var params2 = {
			"page":1,
			"rows":4*rows,
			"flag":"2",
			"systemType":"00",
			"queueId": "duiLie_naocuzhong",
			"scaleAssessStatus": "3"
			//改变工作站接口初始负载数据
		};
		$workBenchServers.ajaxPatientsQueue(params2,$workBenchEvent.ajaxPatientsQueueCallBack);	// 窗口期计划随访患者
	};

	/**
	 * 查看全局配置并且暂存到全局 Global 对象
	 * 因为 window._config 会被覆盖
	 */
	var getWindowConfigAndSetGlobal = function () {
		try {
			var config = JSON.parse(window._config)
			window.__global__  = window.__global__ ? window.__global__ : {}
			for (var key in config) {
				window.__global__[key] = config[key]
			}
		} catch(err) {
			console.log('获取 window.config 失败')
		}
	}

	return workBench;
});
